package com.roger.springcloudGreenwich.oauth.controller;

import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.*;

@ControllerAdvice
@RestController
@RequestMapping("/api/users")
public class UserController {


    /**
     * @return
     */
    @GetMapping("/")
    public String test() {
        return "success";
    }

    public static List<String> findEveryDay(String beginTime, String endTime)
            throws Exception {
        //创建一个放所有日期的集合
        List<String> dates = new ArrayList();

        //创建时间解析对象规定解析格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        //将传入的时间解析成Date类型,相当于格式化
        Date dBegin = sdf.parse(beginTime);
        Date dEnd = sdf.parse(endTime);

        //将格式化后的第一天添加进集合
        dates.add(sdf.format(dBegin));

        //使用本地的时区和区域获取日历
        Calendar calBegin = Calendar.getInstance();

        //传入起始时间将此日历设置为起始日历
        calBegin.setTime(dBegin);

        //判断结束日期前一天是否在起始日历的日期之后
        while (dEnd.after(calBegin.getTime())) {

            //根据日历的规则:月份中的每一天，为起始日历加一天
            calBegin.add(Calendar.DAY_OF_MONTH, 1);

            //得到的每一天就添加进集合
            dates.add(sdf.format(calBegin.getTime()));
            //如果当前的起始日历超过结束日期后,就结束循环
        }
        return dates;
    }

    public static void main(String[] args) throws Exception{
        List<String> everyDay = findEveryDay("2022-12-25","2023-01-26");
        //System.out.println(everyDay);
        AntPathMatcher antPathMatcher = new AntPathMatcher();
        boolean match1 = antPathMatcher.match("/freebytes/**", "/freebytes/1getA");
        boolean match2 = antPathMatcher.match("/freebytes/*/get*", "/freebytes/te/getA");
        boolean match3 = antPathMatcher.match("/freebytes/*/get*", "/freebytes/te/1getA");
        System.out.println(match1);     //true
        System.out.println(match2);     //true
        System.out.println(match3);     //false
    }

    @GetMapping("/redis/buyTicket")
    public String butTicket(){

        return "success:";
    }


}
